eval 'exec perl -wS $0 ${1+"$@"}'
    if 0;

use strict;
use warnings;
use POSIX qw(strftime);

use DBI();
use File::Basename;
use File::stat;
use Data::Dumper 'Dumper';

sub isLuhn
{
    my $number = shift @_;
    my($sum,$odd);
    
    foreach my $n (reverse split(//,$number)) {
#foreach my $n (split(//,$number)) {
        $odd=!$odd;
        if($odd) {
	    $sum+=$n;
        } else {
	    my $x=2*$n;
	    $sum+=$x>9?$x-9:$x;
        }
    }
    
    my $ok = 0+(($sum%10)==0);
    return $ok;
}

#check checksum
my $imei="";
$imei="359568001210990";
#$imei="011291001134651";

if (!isLuhn("$imei"))
{
    print "Bad checksum.\n";
}

else
{
    print "ok.\n";
}
#end check checksum
